package model;

/**
 * @author wujiazhan
 * @className Integrator
 * @description 积分器
 * @date 2021-05-26 10:50
 */
@SuppressWarnings("all")//镇压所有警告
public class Integrator {
    private double integralSum = 0.0; //历史积分总和
    private double pre_val = 0.0; //前一拍的值
    private double samplingTime; //采样时间

    public Integrator(double samplingTime){
        this.samplingTime = samplingTime;
    }//初始化采用时间

    /**
     * 积分总和
     * @param input_cur 当前拍的输入值
     * @return 当前拍的历史积分总和
     */
    public double getIntegralSum(double input_cur){
        double res = (input_cur + pre_val) * samplingTime / 2;
        integralSum += res;
        pre_val = input_cur; //更新状态值
        return integralSum;
    }

    /**
     * 获取前一拍的历史积分值
     *
     * @return double
     */
    public double getPre_val(){
        return pre_val;
    }

    /**
     * 设置前一拍的状态值
     *
     * @param input_val 输入值
     */
    public void setPre_val(double input_val){
        this.pre_val = input_val;
    }

    public void setIntegralSum(double integralSum){
        this.integralSum = integralSum;
    }
}
